package com.infore.water.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.Map;

@Repository
public class UserDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    public Map<String,Object> queryUserByAccountPassword(String account,String password){
        String sql = "select a.id,a.userName,a.realName,isnull(a.phoneNum,'') phoneNum,isnull(a.eamil,'') email,isnull(a.qqnum,'') qqnum,b.name roleName from T_User a left join T_Role b on a.roleId=b.id where a.username=? and a.password=? and enabled=1";
        return jdbcTemplate.queryForMap(sql,account,password);
    }
    public Map<String,Object> queryUserByUserId(String userId){
        String sql = "select id,realName,roleId,password from T_user where id=?";
        return jdbcTemplate.queryForMap(sql,userId);
    }

    public int changePassword(String userId,String newPassword){
        String sql = "update T_User set password=? where id=?";
        return jdbcTemplate.update(sql,newPassword,userId);
    }
}
